<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
session_start();
$CboNodo = $_REQUEST["CboNodo"];

$opcion = $_REQUEST["Opcion"];
//echo $opcion;
switch($opcion) {
    case 1:
        $imagen = "iconos/soloico_grabar.gif";
        $Titulo = "Modificar Usuarios";
        $Oculto = "<input type='hidden' name='Opcion' value='1'>";
        //'sql="select co_perf from solotb_usuario where nu_usua='" & CboNodo & "'"
        //'rw"",sql
        break;
    case 2:
        $imagen = "iconos/soloico_eliminar.gif";
        $Titulo = "Eliminar Usuario";
        $Oculto = "<input type='hidden' name='Opcion' value='2'>";
        break;
    case 3:
        $imagen = "iconos/soloico_grabar.gif";
        $Titulo = "Ingresar Usuario";
        $Oculto = "<input type='hidden' name='Opcion' value='3'>";
        //'rw"",$_REQUEST["max")
        if (empty($_REQUEST["max"])) {
            //$SoloSQL = "select (max(nu_usua)+1) as maximo from solotb_usuario where nodo= $CboNodo";
            $Maximo = SoloFun_Maximo("nu_usua","solotb_usuario");
        }else
            $Maximo = $_REQUEST["max"];
        break;
}


$sql2 = "select active_directory from solotb_usuario_infoadic where nu_usua like '%{$_REQUEST["txtCodigo"]}%'";
//echo $sql2;
$actived = EjecutaSentenciaSql($sql2);

if ($actived == "S")
    $valida = "novalida()";
else
    $valida = "ValidaDatos()";

//'response.write(valida)
//'response.End()
$strsql = "select * from solotb_usuario ";
$strsql .= " where nu_usua= {$_REQUEST["txtCodigo"]} and nodo={$_REQUEST["CboNodo"]}";
//'rw "sql",strsql
//'re
SoloFun_ExecSql ($strsql, $ArrUsuario);

//$strsql = "select * from solotb_nodos";
$strsql = "select * from solotb_nivel1";
SoloFun_ExecSql ($strsql, $SoloArrNodos);
//'rw "",SoloArrNodos(1,0)
//'re
$StrCboNodo = SoloFun_CargaCombo($SoloArrNodos,"CboNodo","$CboDisabled",$itemselec," class='SoloStyle_Texto' style='width:200'","");

/********************Inicio de Consulta de perfiles****************************/
$strsql = "select * from solotb_perfil ";

if (!empty($CboNodo))
    $strsql .= "where nodo = $CboNodo";

$strsql .= " order by ds_perf, nodo asc";

SoloFun_ExecSql2 ($strsql, $ArrPerfil);
//printArray($ArrPerfil);
$itemselec = $ArrUsuario[0][4];
//'   rw"",ArrUsuario(4,0)
if (!empty($_REQUEST["CmbPerfil"])) $itemselec = $_REQUEST["CmbPerfil"];
//'rw"",itemselec
//'re
$StrCboPerfil = SoloFun_CargaCombo($ArrPerfil,"CmbPerfil","$CboDisabled",$itemselec," class='SoloStyle_Texto' style='width:200'","");
?>
<html>
    <head>
        <title>SoloPortal - Modificar Usuarios</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <script type="text/JavaScript" src="PHPMailer/fun_generales.js"></script>
    </head>
    <body topmargin="0" leftmargin="0" onkeydown="checkKey();">
        <img src="templates/SoloTemplate_LogoCabecera.png" style="height: 50px"/>
        <p align="center" class="SoloStyle_TituloPaginas"><?php echo $Titulo; ?></p>

        <form name="frm" action="solotrn_GrabarUsuario.php?CboNodo=<?php echo $_REQUEST["CboNodo"]; ?>" method="POST">
            <?php echo $Oculto; ?>
            <table border="0" width="90%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                    <td><img src="iconos/soloico_salir.gif" border="1" alt="Regresar" style="cursor:hand" onClick="window.opener.location.reload(); window.close();" ><img src="<?php echo $imagen; ?>" border="1" alt="Grabar" style="cursor:hand" onClick="<?php echo $valida; ?>;"> </td>
            </table>
            <table border="0" width="90%" bordercolor="#CCCCCC" cellpadding="2" cellspacing="1" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta" width="25%">Subsecretar&iacute;a/Dir. Provincial</td>
                    <td  class="SoloStyle_EtiquetaCajas" width="75%"><?php echo $StrCboNodo; ?></td>
                </tr>		
                <tr>
                    <td class="SoloStyle_Etiqueta" width="25%"><b>Id Usuario</b></td>
                    <?php
                    if ($opcion == 3)
                        $Codigo = $Maximo;
                    else
                        $Codigo = $ArrUsuario[0][0];
                    ?>
                    <td class="SoloStyle_EtiquetaCajas" width="75%"><?php echo $Codigo;?>
                        <input type="hidden" name="txtCodigo"  maxlength="8" size="12" value="<?php echo $ArrUsuario[0][0];?>" class="SoloStyle_Texto" readonly="true">
                        <input type="hidden" name="Opcion2"  value="<?php echo $opcion;?>">
                    </td>
                </tr>
                <tr>

                    <td class="SoloStyle_Etiqueta"><b>Apellidos y Nombres</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlength="50" size="43" id="ATxtNombre" name="ATxtNombre" class="SoloStyle_Texto" value="<?php echo Str2ProperCase($ArrUsuario[0][2]);?>">
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Usuario</b> </td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlength="20" size="12" id="ATxtUsuario" name="ATxtUsuario" class="SoloStyle_Texto" value="<?php echo $ArrUsuario[0][1];?>">
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Clave</b> </td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="password" maxlength="12" size="12" id="ATxtClave" name="ATxtClave" class="SoloStyle_Texto"  value="<?php echo $ArrUsuario[0][3];?>"
                               <?php if ($actived == "S") {?> disabled="disabled" <?php }?>/>
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Repetir Clave</b> </td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="password" maxlength="12" size="12" id="ATxtClave2" name="ATxtClave2" class="SoloStyle_Texto" value="<?php echo $ArrUsuario[0][3];?>"  <?php if ($actived == "S") { ?> disabled="disabled" <?php } ?>/>
                    </td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Perfil</b> </td>
                    <td class="SoloStyle_EtiquetaCajas"><?php echo $StrCboPerfil; ?> </td>
                </tr>
            </table>
            <br>
        </form>
    </body>
</html>
<script type="text/javascript">
    function ValidaDatos(){
        if (document.getElementById("ATxtClave").value == ""){
            alert ("El campo es requerido");
            document.getElementById("ATxtClave").focus();
            return;
        }

        if (document.getElementById("ATxtClave2").value == ""){
            alert("El campo es requerido");
            document.getElementById("ATxtClave2").focus();
            return;
        }

        if (document.getElementById("ATxtClave").value.length < 5){
            alert("La Longitud de la clave debe ser mayor a 5");
            document.getElementById("ATxtClave").focus();
            return;
        }

        if (document.getElementById("ATxtClave").value != document.getElementById("ATxtClave2").value){
            alert("Las Claves son Diferentes");
            document.getElementById("ATxtClave2").focus();
            return;
        }

        document.frm.submit();

    }

    function novalida(){
        document.frm.submit();
    }

</script>

<?php
include "Includes/soloFun_ShowMessages.php";
?>
